<template>
  <div class="myDiv">
    <tou title="用户基本信息"></tou>
    <div class="chaxun">
      <div class="chaxunleft">
        <van-field v-model="name" placeholder="请输入姓名" label-width="100px" label="姓名" />
        <div>
          <van-radio-group v-model="radio" class="sex">
            <van-radio name="1">男</van-radio>
            <van-radio name="2">女</van-radio>
            <van-radio name>全部</van-radio>
          </van-radio-group>
        </div>
      </div>
      <div class="chaxunright">
        <van-button type="info" size="small" @click="add">添加</van-button>
        <van-button type="info" size="small" style="margin-top: 5px;" @click="selectPatientInfo">查询</van-button>
      </div>
    </div>
    <el-table
      size="mini"
      height="458"
      :data="vesssel"
      v-loading="loading"
      border
      style="width: 100%"
      :stripe="true"
      :cell-style="{padding:'9px 0'}"
      @row-click="godetails"
    >
      <el-table-column align="center" prop="name" fixed label="姓名" width="120"></el-table-column>
      <el-table-column align="center" prop="gender" label="性别">
        <template slot-scope="scope">{{scope.row.gender==1?'男':'女'}}</template>
      </el-table-column>
      <el-table-column align="center" prop="phone" label="手机号" width="100"></el-table-column>
      <el-table-column align="center" prop="age" label="年龄"></el-table-column>
    </el-table>
    <pag :total="total" ref="page" @pagenum="pagenum"></pag>
  </div>
</template>
  
  <script>
import tou from "@/components/header";
import pag from "@/components/pagination";
export default {
  components: { tou, pag },
  props: {},
  data() {
    return {
      radio: "",
      checked: false,
      name: "",
      page: 1,
      rows: 10,
      loading: true,
      total: 0,
      tableData: [], //全部数据
      vesssel: [] //页面临时数据
    };
  },
  watch: {
    page: function() {
      if (this.page == 1) {
        this.vesssel = this.tableData.slice(0, this.rows);
      } else if (this.page == Math.ceil(this.tableData.length / this.rows)) {
        this.vesssel = this.tableData.slice((this.page - 1) * this.rows);
      } else {
        this.vesssel = this.tableData.slice(
          (this.page - 1) * this.rows,
          this.rows * this.page
        );
      }
    }
  },
  computed: {},
  methods: {
    pagenum(data) {
      this.page = data[0];
      this.rows = data[1];
    },
    //
    godetails(data) {
      data.isadd = false;
      this.$router.push({ name: "userdetails", query: data });
    },
    add() {
      this.$router.push({ name: "userdetails", query: { isadd: true } });
    },
    selectPatientInfo() {
      this.$http(this.api.selectPatientInfo, {
        name: this.name,
        gender: this.radio,
        sort: "addtime",
        order: "desc"
      }).then(res => {
        if (res.status === 200) {
          if (res.data.result == "true") {
            this.$refs.page.changecurrent(1);
            this.name = "";
            this.tableData = res.data.pageData.data;
            this.loading = false;
            this.vesssel = this.tableData.slice(0, this.rows);
            this.total = res.data.pageData.total;
          }
        }
      });
    }
  },
  created() {},
  mounted() {
    this.selectPatientInfo();
  }
};
</script>
  <style scoped>
.myDiv {
  padding-bottom: 15px;
}
.chaxun {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.chaxunleft {
  width: 70%;
}
.chaxunright {
  display: flex;
  flex-direction: column;
  align-content: space-between;
}
.tf {
  display: flex;
  align-items: center;
  padding-left: 15px;
  margin-bottom: 10px;
}
.sex {
  display: flex;
  justify-content: space-around;
  margin: 10px 0;
}
</style>